# import rospy
import wx.lib.buttons as buttons
import wx ,cv2                       # 引入wxPython包
import com
class String:
    def __init__(self):
        self.data=""
import rospy
# from std_msgs.msg import String
import time
import datetime
from datetime import datetime

import test
from test import fontstyle

import cmd_sp

def list_to_hex_string(list_data):
    list_str = '[ '
    for x in list_data:
        list_str += '0x{:02X},'.format(x)
    list_str += ' ]'
    return list_str

class HandFrame():
    def __init__(self, p, panel):        # 初始化函数
        self.panel=panel
        self.p=p
        # bmp = wx.Image("lw1.jpeg").ConvertToBitmap()
        # rw = wx.Image("rw.jpeg").ConvertToBitmap()

        # self.button = wx.BitmapButton(panel, -1, bmp, pos=(800, 450))
        # self.button2 = wx.BitmapButton(panel, -1, rw, pos=(700, 450))
        # # 绑定事件，就是指定的button被单击后调用onClick()成员函数
        # panel.Bind(wx.EVT_BUTTON, self.OnClick_lw, self.button)
        # self.button.SetDefault()
        # panel.Bind(wx.EVT_BUTTON, self.OnClick_rw, self.button2)
        # self.button2.SetDefault()
        self.spctl=cmd_sp.sp_ctl()

        ybase=80
        bitmap = wx.StaticBitmap(panel, -1, wx.Bitmap("img/01_手动模式_移动.png", wx.BITMAP_TYPE_ANY), (920, 400-ybase))
        bitmap = wx.StaticBitmap(panel, -1, wx.Bitmap("img/01_手动模式_旋转.png", wx.BITMAP_TYPE_ANY), (620, 400-ybase))

        kb = wx.Bitmap("img/01_按钮01.png")
        kb_press = wx.Bitmap("img/01_按钮02.png")

        kb = wx.Bitmap("img/01_手动模式_上升.png")
        kb_press = wx.Bitmap("img/01_手动模式_上升2.png")
        button = wx.BitmapButton(panel, -1, kb, pos=(620, 200-ybase), size=(
            kb.Width, kb.Height), style=wx.NO_BORDER | wx.BORDER_NONE | wx.BG_STYLE_TRANSPARENT,name="btn_up")
        button.Bind(wx.EVT_LEFT_UP, self.OnClicku)
        button.SetBitmapPressed(kb_press)

        kb = wx.Bitmap("img/01_手动模式_下降.png")
        kb_press = wx.Bitmap("img/01_手动模式_下降2.png")
        button = wx.BitmapButton(panel, -1, kb, pos=(620, 280-ybase), size=(
            kb.Width, kb.Height), style=wx.NO_BORDER | wx.BORDER_NONE | wx.BG_STYLE_TRANSPARENT,name="btn_down")
        button.Bind(wx.EVT_LEFT_UP, self.OnClicku)
        button.SetBitmapPressed(kb_press)

        kb = wx.Bitmap("img/01_手动模式_吸附.png")
        kb_press = wx.Bitmap("img/01_手动模式_吸附中.png")

        self.btn_xifu= wx.BitmapButton(panel, -1, kb, pos=(920, 200-ybase), size=(
            kb.Width, kb.Height), style=wx.NO_BORDER | wx.BORDER_NONE | wx.BG_STYLE_TRANSPARENT,name="btn_xifu")
        self.btn_xifu.Bind(wx.EVT_LEFT_UP, self.OnClicku)
        self.btn_xifu.SetBitmapPressed(kb_press)

        kb = wx.Bitmap("img/01_手动模式_释放.png")
        kb_press = wx.Bitmap("img/01_手动模式_释放2.png")
        button = wx.BitmapButton(panel, -1, kb, pos=(920, 280-ybase), size=(
            kb.Width, kb.Height), style=wx.NO_BORDER | wx.BORDER_NONE | wx.BG_STYLE_TRANSPARENT,name="btn_shifang")
        button.Bind(wx.EVT_LEFT_UP, self.OnClicku)
        button.SetBitmapPressed(kb_press)

        sx, sy = 800, 800

        self.ok_btnu = wx.Panel(panel,  pos=(630, 430-ybase), size=(120, 220),name="btn_lw")
        # self.ok_btnu.BackgroundColour = wx.RED
        self.ok_btnu.Bind(wx.EVT_LEFT_UP, self.OnClick_up)
        self.ok_btnu.Bind(wx.EVT_LEFT_DOWN, self.OnClick_d)

        self.ok_btnd = wx.Panel(panel,  pos=(780, 430-ybase), size=(120, 220),name="btn_rw")
        # self.ok_btnd.BackgroundColour = wx.RED
        self.ok_btnd.Bind(wx.EVT_LEFT_DOWN, self.OnClick_d),self.ok_btnd.Bind(wx.EVT_LEFT_UP, self.OnClick_up)

        self.ok_btnu = wx.Panel(panel,  pos=(930, 520-ybase), size=(100, 50),name="btn_left")
        # self.ok_btnu.BackgroundColour = wx.RED
        self.ok_btnu.Bind(wx.EVT_LEFT_DOWN, self.OnClick_d),self.ok_btnu.Bind(wx.EVT_LEFT_UP, self.OnClick_up)

        self.ok_btnd = wx.Panel(panel,  pos=(1020, 420-ybase), size=(50, 100),name="btn_up")
        # self.ok_btnd.BackgroundColour = wx.RED
        self.ok_btnd.Bind(wx.EVT_LEFT_DOWN, self.OnClick_d),self.ok_btnd.Bind(wx.EVT_LEFT_UP, self.OnClick_up)

        self.ok_btnx = wx.Panel(panel,  pos=(1020, 560-ybase), size=(50, 100),name="btn_down")
        # self.ok_btnx.BackgroundColour = wx.RED
        self.ok_btnx.Bind(wx.EVT_LEFT_DOWN, self.OnClick_d),self.ok_btnx.Bind(wx.EVT_LEFT_UP, self.OnClick_up)

        self.ok_btnf = wx.Panel(panel,  pos=(1070, 520-ybase), size=(100, 50),name="btn_right")
        # self.ok_btnf.BackgroundColour = wx.RED
        self.ok_btnf.Bind(wx.EVT_LEFT_DOWN, self.OnClick_d),self.ok_btnf.Bind(wx.EVT_LEFT_UP, self.OnClick_up)

        # self.pub = rospy.Publisher("chatter", String, queue_size=10)
        self.msg = String()  # 创建 msg 对象
        self.img_yixifu = wx.Bitmap("img/01_手动模式_已吸附.png")

    def OnClicku(self, event):

        button = event.GetEventObject()
        label = button.GetName()

        if label=="btn_down":
            print(label,list_to_hex_string(com.Y0_ON))
            # bitmap = wx.StaticBitmap(self.panel, -1, wx.Bitmap("img/01_手动模式_移动2.png", wx.BITMAP_TYPE_ANY), (920, ybase))
        if label=="btn_up":
            print(label,list_to_hex_string(com.Y1_ON))
            # bitmap = wx.StaticBitmap(self.panel, -1, wx.Bitmap("img/01_手动模式_移动1.png", wx.BITMAP_TYPE_ANY), (920, ybase))
        if label=="btn_xifu":
            print(label,list_to_hex_string(com.Y1_ON))
            self.p.xifuzhuangtai.SetLabel("正在吸附")
            self.p.Update()
            # self.p.Update()
            ret=com.xifu()
            if ret ==0:
                self.p.xifuzhuangtai.SetLabel("已吸附")
                self.btn_xifu.SetBitmapFocus(self.img_yixifu )
            # bitmap = wx.StaticBitmap(self.panel, -1, wx.Bitmap("img/01_手动模式_移动3.png", wx.BITMAP_TYPE_ANY), (920, ybase))
        if label=="btn_shifang":
            self.p.xifuzhuangtai.SetLabel("正在释放")
            # self.p.Update()
            self.p.Update()
            ret=com.shifang()
            if ret ==0:
                self.p.xifuzhuangtai.SetLabel("已释放")
            # bitmap = wx.StaticBitmap(self.panel, -1, wx.Bitmap("img/01_手动模式_移动4.png", wx.BITMAP_TYPE_ANY), (920, ybase))
            print(label,list_to_hex_string(com.Y1_ON))
        # print("u", event)
        # self.msg.data = "u"
        # self.pub.publish(self.msg)


    def OnClick_up(self, event):
        ybase=80
        self.spctl.set(0,0.0,0.0)
        bitmap = wx.StaticBitmap(self.panel, -1, wx.Bitmap("img/01_手动模式_移动.png", wx.BITMAP_TYPE_ANY), (920, 400-ybase))
        bitmap = wx.StaticBitmap(self.panel, -1, wx.Bitmap("img/01_手动模式_旋转.png", wx.BITMAP_TYPE_ANY), (620, 400-ybase))
        # button = event.GetEventObject()
        # label = button.GetName()
        # if label=="btn_down":
        #     bitmap = wx.StaticBitmap(self.panel, -1, wx.Bitmap("img/01_手动模式_移动2.png", wx.BITMAP_TYPE_ANY), (920, ybase))
        # if label=="btn_up":
        #     bitmap = wx.StaticBitmap(self.panel, -1, wx.Bitmap("img/01_手动模式_移动1.png", wx.BITMAP_TYPE_ANY), (920, ybase))
        # if label=="btn_left":
        #     bitmap = wx.StaticBitmap(self.panel, -1, wx.Bitmap("img/01_手动模式_移动3.png", wx.BITMAP_TYPE_ANY), (920, ybase))
        # if label=="btn_right":
        #     bitmap = wx.StaticBitmap(self.panel, -1, wx.Bitmap("img/01_手动模式_移动4.png", wx.BITMAP_TYPE_ANY), (920, ybase))
        # if label=="btn_rw":
        #     bitmap = wx.StaticBitmap(self.panel, -1, wx.Bitmap("img/01_手动模式_旋转2.png", wx.BITMAP_TYPE_ANY), (620, ybase))
        # if label=="btn_lw":
        #     bitmap = wx.StaticBitmap(self.panel, -1, wx.Bitmap("img/01_手动模式_旋转3.png", wx.BITMAP_TYPE_ANY), (620, ybase))
        # print("d",label)
        # self.msg.data = "u"
    def OnClick_d(self, event):
        ybase=400-80
        speed=self.p.cfg.getNode('speed').real()
        print(speed)
        button = event.GetEventObject()
        label = button.GetName()
        if label=="btn_down":
            bitmap = wx.StaticBitmap(self.panel, -1, wx.Bitmap("img/01_手动模式_移动2.png", wx.BITMAP_TYPE_ANY), (920, ybase))
            self.spctl.set(-speed,0.0,0.0)
        if label=="btn_up":
            self.spctl.set(speed,0.0,0.0)
            bitmap = wx.StaticBitmap(self.panel, -1, wx.Bitmap("img/01_手动模式_移动1.png", wx.BITMAP_TYPE_ANY), (920, ybase))
        if label=="btn_left":
            self.spctl.set(0.0,speed,0.0)
            bitmap = wx.StaticBitmap(self.panel, -1, wx.Bitmap("img/01_手动模式_移动3.png", wx.BITMAP_TYPE_ANY), (920, ybase))
        if label=="btn_right":
            self.spctl.set(0.0,-speed,0.0)
            bitmap = wx.StaticBitmap(self.panel, -1, wx.Bitmap("img/01_手动模式_移动4.png", wx.BITMAP_TYPE_ANY), (920, ybase))
        if label=="btn_rw":
            self.spctl.set(0.0,0,speed)
            bitmap = wx.StaticBitmap(self.panel, -1, wx.Bitmap("img/01_手动模式_旋转2.png", wx.BITMAP_TYPE_ANY), (620, ybase))
        if label=="btn_lw":
            self.spctl.set(0.0,0,-speed)
            bitmap = wx.StaticBitmap(self.panel, -1, wx.Bitmap("img/01_手动模式_旋转3.png", wx.BITMAP_TYPE_ANY), (620, ybase))
        print("d",label)
        self.msg.data = "u"
        # self.pub.publish(self.msg)
        

class AutoFrame():
    def __init__(self, p, panel):        # 初始化函数
        self.p=p
        self.panel=panel
        self.kb = wx.Bitmap("img/01_自动模式_编辑.png")
        self.kb_press = wx.Bitmap("img/01_自动模式_编辑2.png")
        self.button = wx.BitmapButton(panel, -1, self. kb, pos=(1000,550), size=(self. kb.Width, self.kb.Height), style=wx.NO_BORDER | wx.BORDER_NONE | wx.BG_STYLE_TRANSPARENT,name="btn_edit")
        self.button.SetBitmapPressed(self.kb_press)
        
        self.button.Bind(wx.EVT_LEFT_UP, self.OnClick)

        self.kb = wx.Bitmap("img/01_自动模式_目的地.png")
        self.kb_press = wx.Bitmap("img/01_自动模式_目的地2.png")
        self.panel_auto = wx.Panel(panel, -1, size=(500, 300), pos=(40, 100))
        # self.panel_auto.SetBackgroundColour("#009000")                # 红色
        self.panel_auto = wx.Panel(panel, -1, size=(500, 300), pos=(340, 100))
        # self.panel_auto.SetBackgroundColour("#0390f0")                # 红色
        # self.checkbox1 = wx.CheckBox(parent=panel,
        #                              id=-1,
        #                              label=u"自动交接",
        #                              size=(120, 40),
        #                              pos=(360, 50))
        # self.checkbox2 = wx.CheckBox(parent=panel,
        #                              id=-1,
        #                              label=u"接取",
        #                              size=(120, 40),
        #                              pos=(460, 50))
        # self.checkbox3 = wx.CheckBox(parent=panel,
        #                              id=-1,
        #                              label=u"放置",
        #                              size=(120, 40),
        #                              pos=(640, 50))


        # self.getbutton(panel, 1)
        # self.getbutton(panel, 2)
        # self.getbutton(panel, 3)
        # self.getbutton(panel, 4)
        self.ad=test.EditTask1(self.p)
        self.ad.Hide()
        self.tasks=[]
        # self.getbutton(panel, 5)
        # self.getbutton(panel, 6)
        # self.getbutton(panel, 7)
        # text2 = wx.StaticText(panel, wx.ID_ANY, "目的地1", (400, 30))
        # text2.SetForegroundColour("White")
        # text2.SetBackgroundColour("Black")
        # text2 = wx.StaticText(panel,
        #                       wx.ID_ANY,
        #                       "目的地2",
        #                       (600, 130))
        # text2.SetForegroundColour("White")
        # text2.SetBackgroundColour("Black")
        # self.pub = rospy.Publisher("chatter", String, queue_size=10)
        self.okds=test.OKTask1(self.p)
        # print("aaaaaaaaaaaaaaaaaaaaaa")
        # self.okds.ShowWindowModal()
        self.okds.Hide()

    def getbutton(self, panel, label):
        # md = int(idx/2)
        # if idx % 2 == 0:
        idx=len(self.tasks)-1
        if (idx>4):
            return
        _pos = (620, 100+90*idx)
        # else:
        #     _pos = (920, 200+80*(md))
        task=self.tasks[-1]
        button = wx.BitmapButton(panel, -1, self. kb, pos=_pos, size=(
            self. kb.Width, self.kb.Height), style=wx.NO_BORDER | wx.BORDER_NONE | wx.BG_STYLE_TRANSPARENT,name=task.name)
        button.SetBitmapPressed(self.kb_press)
        tx = TransparentText(panel, -1, label=label,
                               pos=(_pos[0]+150, _pos[1]+25), size=(self.kb.Width, self. kb.Height))
        fontstyle(tx)
        panel.Bind(wx.EVT_BUTTON, self.OnClick, button)
    def s(self):
        self.ad.task=None
        self.ad.ShowWindowModal()
        if self.ad.task is None:
            return
        self.tasks.append(self.ad.task)
        self.getbutton(self.panel,self.ad.task.name)
        print(self.ad.task.name)
        # self.ad.Destroy()
    def OnClick(self, event):
        button = event.GetEventObject()
        label = button.GetName()
        if label=="btn_edit":
            wx.CallLater(0, self.s)
            print("a")
        for t in self.tasks:
            if label==t.name:
                # okds=test.OKTask1()
                self.okds.init_ui("确认执行该任务吗？")
                self.okds.ShowWindowModal()
                if self.okds.ok:
                    print("执行 ",label)
                else:
                    print("取消 ",label)
                print("a")
        # self.kb_press = wx.Bitmap("img/01_自动模式_编辑2.png")
        # self.button.SetBitmapPressed(self.kb_press)

        # button = wx.BitmapButton(self.panel, -1, self. kb, pos=(1000,550), size=(self. kb.Width, self.kb.Height), style=wx.NO_BORDER | wx.BORDER_NONE | wx.BG_STYLE_TRANSPARENT,name="btn_edit")
        # button.SetBitmapPressed(self.kb_press)
        # button.Bind(wx.EVT_LEFT_UP, self.OnClick)
        # # self.msg.data = "u"
        # self.pub.publish(self.msg)

import cam
class MainFrame(wx.Frame):
    def __init__(self, p=None, t=u""):        # 初始化函数
        wx.Frame.__init__(self, id=-1, parent=p, title=t, pos=(300, 100),
                          size=(1280, 800))  # , style=wx.SIMPLE_BORDER
        self.Center(wx.CURSOR_WAIT)
        self.SetMaxSize((1280, 800))
        self.SetMinSize((1280, 800))
        to_bmp_image = wx.Bitmap(
            "img/02.png", wx.BITMAP_TYPE_ANY)
        bitmap = wx.StaticBitmap(self, -1, to_bmp_image, (0, 0))
        self.cfg = cv2.FileStorage('config.yaml', cv2.FileStorage_READ)
        cam_topic1=self.cfg.getNode('cam1').string()
        cam_topic2=self.cfg.getNode('cam2').string()
        self.cam=cam.cam(cam_topic1,name="pl")
        self.cam1=cam.cam(cam_topic2,name="pr")

        # self.Bind(wx.EVT_BUTTON,self.OnClose,Close_Button)
        wx.CallLater(500, self.calllog, 'call after 100ms', name="test")

        

    def Notify(self):
        t = time.localtime(time.time())
        week_list = ["星期日","星期一","星期二","星期三","星期四","星期五","星期六","星期日"]
        year=time.localtime().tm_year#既可以获取当前年份，也可以指定年份
        month=time.localtime().tm_mon#既可以获取当前月份，也可以指定年月份
        day=time.localtime().tm_mday#既可以获取当前天数，也可以指定天数
        date =datetime.date(datetime(year=year,month=month,day=day))
        # print(date.isoweekday())
        self.day.SetLabelText(time.strftime("%Y-%m-%d") +" "+week_list[date.isoweekday()])
        self.data.SetLabelText(time.strftime("%H:%M:%S"))
        self.speed.SetLabel("车速:%.2f" % (13.2))
        self.height.SetLabel("车速:%.2f" % (0.2))
        # self.xifuzhuangtai.SetLabel("吸附状态:ok")
    def calllog(self, *args, **kwargs):
        # ad=test.DialogControl(self)
        # ad.ShowWindowModal()
        # if not ad.ok:
        #     del ad
        #     wx.CallLater(500, self.calllog, 'call after 100ms', name="test")
        #     return
        
        self.callmain('call after 100ms', name="test")
        # wx.CallLater(500, self.callmain, 'call after 100ms', name="test")
    def _count_task(self,evt):
        self.vb.pal.Show()
        print("aaaaaaaaaaaaaaaaaaaaaa")

    def generatebtcl(self, ev):

        print(ev)
        self.callmain('call after 100ms', name="test")

    def callmain(self, *args, **kwargs):
        message = repr(args) + repr(kwargs)
        print(message)
        # to_bmp_image = wx.Image(
        #     "auto.jpeg", wx.BITMAP_TYPE_ANY).Resize((1280, 800), (0, 0))
        # to_bmp_image = to_bmp_image.Scale(
        #     1280, 800, wx.IMAGE_QUALITY_HIGH).ConvertToBitmap()
        # self.auto_bg = wx.StaticBitmap(frame, -1, to_bmp_image, (0, 0))
        img=wx.Bitmap("img/01_bg.png")
        
        self.panel_auto = wx.Panel(self, -1, size=(1280, 80), pos=(0, 0))
        self.hand_bg = wx.StaticBitmap(
            self.panel_auto, -1, img, (0, 0))
        
        self.panel_auto = wx.Panel(self, -1, size=(1280, 800), pos=(0, 80))
        # self.panel_auto.BackgroundColour = wx.RED
        self.panel_hand = wx.Panel(self, -1, size=(1280, 800), pos=(0, 80))

        to_bmp_image = wx.Bitmap(
            "img/01_bg.png")
        self.hand_bg = wx.StaticBitmap(
            self.panel_hand, -1, to_bmp_image, (0, -80))
        self.hand_bg = wx.StaticBitmap(
            self.panel_auto, -1, to_bmp_image, (0, -80))
        # self.hand_bg.Show(False)

        # self.panel_auto.SetBackgroundColour("#009093")                # 红色

        to_bmp_image = wx.Bitmap(
            "img/01a_bg.png")
        # to_bmp_image = to_bmp_image.Scale(
        #     1280, 800, wx.IMAGE_QUALITY_HIGH).ConvertToBitmap()
        self.auto_bg = wx.StaticBitmap(
            self.panel_auto, -1, to_bmp_image, (0, -80))

        # self.panel_hand.SetBackgroundColour("#007093")                # 红色
        # self.panel_auto.set
        # self.SetBackgroundStyle()

        self.panel = wx.Panel(self.panel_hand,  pos=(570, 10), size=(330, 50),name="btn_auto")
        # self.panel.BackgroundColour = wx.RED
        self.panel.Bind(wx.EVT_LEFT_UP, self.OnClick)
        # p1=wx.StaticText(self.panel_hand, wx.ID_ANY, "自动模式", (690, 100),size=(100,30))
        # fontstyle(p1)
        self.panel = wx.Panel(self.panel_auto,  pos=(930, 10), size=(320, 50),name="btn_hand")
        # self.panel.BackgroundColour = wx.RED

        self.pan_exit = wx.Panel(self,  pos=(480, 0), size=(300, 50))
        # self.pan_exit.BackgroundColour = wx.RED
        self.pan_exit.Bind(wx.EVT_LEFT_UP, self.exit)
        print(self.pan_exit)

        # self.panel.BackgroundColour = wx.BLUE
        self.panel.Bind(wx.EVT_LEFT_UP, self.OnClick)
        # p1=wx.StaticText(self.panel_auto, wx.ID_ANY, "手动模式", (1050, 100),size=(100,30))
        # fontstyle(p1)

        # self.ok_btn = wx.Button(self.panel_hand, -1,
        #                         "自动模式", (690, 100), (100, 40))
        # self.Bind(wx.EVT_BUTTON, self.OnClick, self.ok_btn)
        # self.ok_btn = buttons.GenBitmapTextButton(self.panel_auto, -1,None,
        #                         "手动模式", (1050, 100), (100, 40))
        # self.Bind(wx.EVT_BUTTON, self.OnClick2, self.ok_btn)
        # self.ok_btn.SetTransparent(True)
        self.hf = HandFrame(self, self.panel_hand)
        self.af = AutoFrame(self, self.panel_auto)
        # self.panel_auto.Show(True)
        # self.panel_hand.Show(False)
        # self.data1 = wx.StaticText(
        #     self, wx.ID_ANY, "AGV机器人系统", (550, 13), size=(300, 30))

        # self.data1 = wx.StaticText(self, wx.ID_ANY, "顶板高度", (160, 20),size=(100,30))
        # self.data1 = wx.StaticText(self, wx.ID_ANY, "顶板高度", (160, 20),size=(100,30))
        # self.data1.SetFont(
        #     wx.Font(20, wx.DECORATIVE, style=wx.NORMAL, weight=wx.BOLD))
        # self.data1.SetForegroundColour("White")

        # self.data1 = wx.StaticText(
        #     self, wx.ID_ANY, "实时参数", (262, 110), size=(200, 30))
        # self.data1.SetFont(
        #     wx.Font(20, wx.DECORATIVE, style=wx.NORMAL, weight=wx.BOLD))
        # self.data1.SetForegroundColour("White")
        heig=18
        self.day = wx.StaticText(
            self, wx.ID_ANY, "时间", (900, heig), size=(100, 30))
        self.data = wx.StaticText(
            self, wx.ID_ANY, "日期", (1100, heig+3), size=(100, 30))
        self.dianchi = wx.StaticText(
            self, wx.ID_ANY, "30%", (1220, heig+3), size=(100, 30))
        self.speed = wx.StaticText(
            self, wx.ID_ANY, "车速", pos=(20, heig), size=(100, 30))
        self.height = wx.StaticText(
            self, wx.ID_ANY, "顶板高度", (160, heig), size=(100, 30))

        # bitmap = wx.EmptyBitmap(650, 100)
        # button = wx.BitmapButton(self, -1, bitmap=bitmap, pos=(100, 0), size=(650, 100), style=0)
        self.xifuzhuangtai = wx.StaticText(
            self, wx.ID_ANY, "吸附状态:", (280, heig), size=(140, 30))
        fontstyle(self.xifuzhuangtai)
        self.xifuzhuangtai = wx.StaticText(
            self, wx.ID_ANY, "", (380, heig), size=(140, 30))
        fontstyle(self.dianchi)
        fontstyle(self.day)
        fontstyle(self.speed)
        fontstyle(self.height)
        fontstyle(self.xifuzhuangtai)
        fontstyle(self.data)
        # 普通定时器，循环调用该函数Notify，会一直进行循环
        self.timer = wx.PyTimer(self.Notify)  # 创建定时器
        self.timer.Start(1000)  # 设置间隔时间
        # text2 = wx.StaticText(self, wx.ID_ANY, "电压", (0, 50))
        #      wxBitmap bitmap(wxT("res\\datagrow_fill.png"),wxBITMAP_TYPE_PNG);
        # rospy.init_node("talker_p")
        # 3.实例化 发布者 对象
        # self.pub = rospy.Publisher("chatter",String,queue_size=10)
        # 4.组织被发布的数据，并编写逻辑发布数据
        # btn = wx.StaticText(self, wx.ID_ANY, "进行中", (10, 530))
        # btn = wx.StaticText(self, wx.ID_ANY, "交接中", (80, 530))
        # btn = wx.StaticText(self, wx.ID_ANY, "任务完成", (210, 530))

        msg_front = "hello 你好"
        count = 0  # 计数器
        # rate = rospy.Rate(1)
        # rospy.sleep(1)
        # while not rospy.is_shutdown():

        # rate.sleep()
        # rospy.loginfo("写出的数据：%s",msg.data)
        count += 1
        kb=wx.Bitmap("img/01_实时_前摄像头.png")
        bmp=wx.Bitmap("img/01_实时_前摄像头2.png")
        sx=50
        button = wx.BitmapButton(self,-1,kb ,pos=(sx,650),size=(bmp.Width, bmp.Height),style=wx.NO_BORDER|wx.BORDER_NONE|wx.BG_STYLE_TRANSPARENT,name="btn_qian")
        # t=TransparentText(self,-1,label=label, pos=(90, 650),size=(60,60))
        # fontButton = wx.Font(17,wx.SWISS,wx.NORMAL,wx.NORMAL)
        # t.SetFont(fontButton)
        button.Bind(wx.EVT_LEFT_UP, self.OnClick)

        kb=wx.Bitmap("img/01_实时_后摄像头.png")
        bmp=wx.Bitmap("img/01_实时_后摄像头2.png")
        button = wx.BitmapButton(self,-1,kb ,pos=(sx+150,650),size=(bmp.Width, bmp.Height),style=wx.NO_BORDER|wx.BORDER_NONE|wx.BG_STYLE_TRANSPARENT,name="btn_hou")
        kb=wx.Bitmap("img/01_实时_结束任务.png")
        bmp=wx.Bitmap("img/01_实时_结束任务2.png")
        button.Bind(wx.EVT_LEFT_UP, self.OnClick)

        button = wx.BitmapButton(self,-1,kb ,pos=(sx+150*2,650),size=(bmp.Width, bmp.Height),style=wx.NO_BORDER|wx.BORDER_NONE|wx.BG_STYLE_TRANSPARENT,name="btn_over")
        # t=TransparentText(self,-1,label=label, pos=(90+150, 650),size=(60,60))
        # fontButton = wx.Font(17,wx.SWISS,wx.NORMAL,wx.NORMAL)
        # t.SetFont(fontButton)
        button.Bind(wx.EVT_LEFT_UP, self.OnClick)
    def OnClick(self,event):
        button = event.GetEventObject()
        label = button.GetName()
        print(label)
        if label=="btn_hou":
            self.cam.s()
        if label=="btn_qian":
            self.cam1.s()
        if label=="btn_auto":
                # self.hand_bg.Show(True)
            self.panel_auto.Show(True)
            self.panel_hand.Show(False)
            print("A")

            msg = String()  # 创建 msg 对象
            msg.data = "手动模式"
            # self.pub.publish(msg)
        if label=="btn_hand":
            self.panel_hand.Show(True)
            self.panel_auto.Show(False)
            msg = String()  # 创建 msg 对象
            msg.data = "自动模式"
            # self.hand_bg.Show(False)
            # self.pub.publish(msg)
            print("自动模式")
        if label=="btn_over":

            print("结束任务")
    def exit(self,e):
        # self.Destroy()
        self.calllog("a")
class TransparentText(wx.StaticText):  # 继承了wx.Statictext的类，并对相应的方法进行重写;
    def __init__(self, parent, id=wx.ID_ANY, label='', pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.TRANSPARENT_WINDOW, name='transparenttext'):
        wx.StaticText.__init__(self, parent, id, label, pos, size, style, name)
        self.Bind(wx.EVT_PAINT, self.on_paint)
        self.Bind(wx.EVT_ERASE_BACKGROUND, lambda event: None)
        self.Bind(wx.EVT_SIZE, self.on_size)

    def on_paint(self, event):  # 重写on_paint可以对控件进行重写重新构造形状
        bdc = wx.PaintDC(self)
        dc = wx.GCDC(bdc)
        font_face = self.GetFont()
        font_color = self.GetForegroundColour()
        dc.SetFont(font_face)
        dc.SetTextForeground(font_color)
        dc.DrawText(self.GetLabel(), 0, 0)

    def on_size(self, event):
        self.Refresh()
        event.Skip()
class VirtualKeyboard:
    def __init__(self,pal):
        # self.pal=pal
        # 创建虚拟键盘的按键
        # self.keymap={'del':{'lb':""}}
        self.buttons = [
            ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0'],
            ['q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p'],
            ['a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l','del'],
            ['z', 'x', 'c', 'v', 'b', 'n', 'm'],
        ]
        img = wx.Bitmap("img/03_键盘.png")
        ics=240
        iy=440

        self.pal=wx.Panel(pal,-1,pos=(ics-20, iy-20), size=(img.Width, img.Height))
        # 创建虚拟键盘的UI
        # self.pal.SetBackgroundColour('black')
        bitmap = wx.StaticBitmap(self.pal, -1, img)
        self.init_ui()

    def init_ui(self):
        bmp=wx.Bitmap("img/03_键盘_按钮2.png")

        kb=wx.Bitmap("img/03_键盘_按钮.png")
        ics=0+10
        iy=10

        fontButton = wx.Font(17,wx.SWISS,wx.NORMAL,wx.NORMAL)
        for row in self.buttons:
            for label in row:
                # button = btns.GenBitmapTextButton(self,-1,None ,label=label,size=(kb.Width, kb.Height),style=wx.BORDER_NONE|wx.BG_STYLE_TRANSPARENT)
                button = wx.BitmapButton(self.pal,-1,kb ,size=(bmp.Width, bmp.Height),style=wx.NO_BORDER|wx.BORDER_NONE|wx.BG_STYLE_TRANSPARENT)
                t=TransparentText(self.pal,-1,label=label, pos=(0, 0),size=(60,60))
                    # self.inputb1 = buttons.GenBitmapTextButton(self.panel, -1, None, "Import", pos=(380, 75),
                                                #    size=(150, 25))
                button.SetLabel(label)
                button.SetPosition((ics,iy))
                t.SetPosition((int(ics+kb.Width/2-10),int(iy+kb.Height/2-20)))
                t.SetFont(fontButton)
                ics+=kb.Width+10
                # button.SetBitmapPressed(bmp)
                # hbox.Add(button, proportion=1, flag=wx.ALL, border=3)
                button.SetBitmapPressed(bmp)
                # button.SetBitmapFocus(bmp)
                # button.SetBitmapSelected(bmp)
                # button.SetBitmapSelected(bmp)
                button.Bind(wx.EVT_BUTTON, self.on_press)
            # vbox.Add(hbox, proportion=1, flag=wx.EXPAND)
            iy+=kb.Width+10
            ics=10
        print("ics:",ics,iy)
        iy-=kb.Width+10
        ics=10+(kb.Width+10)*8+kb.Width-25
        label="确认"
        bmp=wx.Bitmap("img/03_键盘_大按钮2.png")
        kb=wx.Bitmap("img/03_键盘_大按钮.png")
        button = wx.BitmapButton(self.pal,-1,kb ,size=(bmp.Width, bmp.Height),style=wx.NO_BORDER|wx.BORDER_NONE|wx.BG_STYLE_TRANSPARENT)
        t=TransparentText(self.pal,-1,label="确认", pos=(0, 0),size=(60,60))
        button.SetLabel(label)
        button.SetPosition((ics,iy))
        t.SetPosition((int(ics+kb.Width/2-20),int(iy+kb.Height/2-20)))
        t.SetFont(fontButton)
        button.SetBitmapPressed(bmp)
        button.Bind(wx.EVT_BUTTON, self.on_press)
        
      
        # ics=10+(kb.Width+10)*6+kb.Width-20
        ics-=(kb.Width+10)
        label="取消"
        button2 = wx.BitmapButton(self.pal,-1,kb ,size=(bmp.Width, bmp.Height),style=wx.NO_BORDER|wx.BORDER_NONE|wx.BG_STYLE_TRANSPARENT)
        t=TransparentText(self.pal,-1,label=label, pos=(0, 0),size=(60,60))
        button2.SetLabel(label)
        button2.SetPosition((ics,iy))
        t.SetPosition((int(ics+kb.Width/2-20),int(iy+kb.Height/2-20)))
        t.SetFont(fontButton)
        ics+=kb.Width+5
        button2.SetBitmapPressed(bmp)
        button2.Bind(wx.EVT_BUTTON, self.on_press)

    def on_press(self, event):
        button = event.GetEventObject()
        label = button.GetLabel()
        if label=="确认":
            self.pal.Hide()
        if label=="取消":
            self.pal.Hide()
        print(f'Pressed: {label}')


if __name__ == "__main__":
    # com.ser_init()
    # 创建一个应用程序
    app = wx.App(False)
    # frame就是应用程序的主窗口
    com.ser_init()
 
    frame = MainFrame()
    frame.Show()        # 显示主窗口
    # time.sleep(1)
    app.MainLoop()        # 开始消息循环
    com.serial_close()